//
//  ZZCChangePayPwdController.m
//  ZZC-Finance
//
//  Created by a on 2017/9/7.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCChangePayPwdController.h"
#import "ZZCMeController.h"
@interface ZZCChangePayPwdController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPayPwdTFD;
@property (weak, nonatomic) IBOutlet UITextField *nnewPayPwdTFD;
@property (weak, nonatomic) IBOutlet UITextField *reNewPayPwdTFD;

@end

@implementation ZZCChangePayPwdController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改支付密码";
    self.oldPayPwdTFD.secureTextEntry = YES;
    self.nnewPayPwdTFD.secureTextEntry = YES;
    self.reNewPayPwdTFD.secureTextEntry = YES;

}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (IBAction)clickAction:(UIButton *)sender {
    ZZCLog(@"确认");
    if ([self.nnewPayPwdTFD.text isEqualToString:
         self.reNewPayPwdTFD.text]) {
        NSString *token = ZZCNSUserDefaults(@"token");
        NSDictionary *dict = @{@"token":token,
                               @"old_pay_password":self.oldPayPwdTFD.text,
                               @"new_pay_password":self.nnewPayPwdTFD.text};
        NSString *sign = [ZZCRequest getSignWithDict:dict];
        sign = [NSString md5:[sign lowercaseString]];
        NSDictionary *param = @{@"timestamp":[NSString timeStr],@"sign":sign,
                                @"token":token,
                                @"old_pay_password":self.oldPayPwdTFD.text,
                                @"new_pay_password":self.nnewPayPwdTFD.text};
        [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_CHANGPASSWORD parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
            if (error) {
                ZZCLog(@"失败-%@",error);
            }else {
                ZZCLog(@"-%@",responseObject);
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                if ([responseObject[@"code"] isEqual:@(200)]) {
                    for (UIViewController *controller in self.navigationController.viewControllers) {
                        if ([controller isKindOfClass:[ZZCMeController class]]) {
                            [self.navigationController popToViewController:controller animated:YES];
                            //这里可以做回到登录界面的一些数据操作
                        }
                    }
                }

            }
            
        }];
        
    }else {
        [UIAlertController showInfoAlertLoginVC:self title:@"提示" message:@"两次输入的密码不一样" ok:nil];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
